﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
//using System.Linq;
using System.Text;
using System.Windows.Forms;
//new
using MyRegester;
using System.IO;
using ZoomPicBox;
using System.Xml;
using System.Collections;
using DataInterfaceDLL;

namespace JKZP
{
    public partial class Form_Main : Form
    {
        Timer m_systemTimer;
        JKCamera m_CurrentCam;
        int speed = 4;
        int I = 0;//抓拍组序号
        const int cMaxSpeed = 8;
        const int cMinSpeed = 1;
        int[] index = new int[5];

        DateTime[] m_WFSJ = new DateTime[5];//违法时间，取第二张图片的时间
        Point pointStart;
        Point pointEnd;
        bool m_FlagRect;
        aitmskdws.aitmskdws kdws = null;
        Font font = new Font("Arial", 25);
        int SplitterDistance1;
        int SplitterDistance2;

        //DSS
        public int m_nSmartWndId = -1;    //窗口
        public int m_nInit = -1;          //初始化
        public int m_nLogin = -1;         //登陆
        public int m_nLoadTree = -1;      //加载组织结构
        public string m_TreeString = "";     //组织结构
        Hashtable ht_channel = new Hashtable();//通道名称表
        public string m_camid = "";   //当前camid;
        string FileName1 = "";
        string FileName2 = "";
        string FileName3 = "";
        //自动切换CAM变量
        string[] indexIP = new string[5];
        JKCamera[] a_CurrentCam = new JKCamera[5];


        public Form_Main()
        {
            InitializeComponent();
        }

        private void Form_Main_Load(object sender, EventArgs e)
        {
            try
            {
                //时间显示
                m_systemTimer = new Timer();
                m_systemTimer.Interval = 1000;
                m_systemTimer.Tick += new EventHandler(m_systemTimer_Tick);
                m_systemTimer.Start();

                index[0] = 0;
                index[1] = 0;
                index[2] = 0;
                index[3] = 0;
                index[4] = 0;



                m_WFSJ[0] = DateTime.Now;
                m_WFSJ[1] = DateTime.Now;
                m_WFSJ[2] = DateTime.Now;
                m_WFSJ[3] = DateTime.Now;
                m_WFSJ[4] = DateTime.Now;

                //路口树
                UpDateTree();

                //初始化SDK
                PP.DHSDKInit();
                PP.HKSDKInit();

                //默认号牌号码显示
                textBox_hphm.Text = PP.gDefaultHPHM;

                //违法行为
                string[] wfxwdm = File.ReadAllLines(PP.gWFXWDMFile);
                if (wfxwdm != null)
                {
                    comboBox_wfxw.MouseWheel += new MouseEventHandler(comboBox_wfxw_MouseWheel);
                    comboBox_wfxw.Items.Clear();
                    comboBox_wfxw.Items.AddRange(wfxwdm);
                    comboBox_wfxw.SelectedIndex = 0;
                }

                string[] hpzl = File.ReadAllLines(PP.gHPZLFile);
                if (hpzl != null)
                {
                    comboBox_hpzl.MouseWheel += new MouseEventHandler(comboBox_hpzl_MouseWheel);
                    comboBox_hpzl.Items.Clear();
                    comboBox_hpzl.Items.AddRange(hpzl);
                    comboBox_hpzl.SelectedIndex = 1;
                }

                //检查注册
                RegMgr.m_LocalIP = PP.gLocalIP;
                RegMgr.m_RegNode = PP.gRegNode;
                PP.gSoftRegstor = RegMgr.SoftRegstered;
                SetSystemEnable(true, PP.gUser.admin);
                //SetSystemEnable(PP.gSoftRegstor, PP.gUser.admin);


                //3D
                pointStart = new Point(0, 0);
                pointEnd = new Point(0, 0);
                m_FlagRect = false;

                this.zoomPictureBox_1_1.pictureBox1.DoubleClick += new EventHandler(zoomPictureBox_1_1_DoubleClick);
                this.zoomPictureBox_1_2.pictureBox1.DoubleClick += new EventHandler(zoomPictureBox_1_2_DoubleClick);
                this.zoomPictureBox_1_3.pictureBox1.DoubleClick += new EventHandler(zoomPictureBox_1_3_DoubleClick);

                this.zoomPictureBox_2_1.pictureBox1.DoubleClick += new EventHandler(zoomPictureBox_2_1_DoubleClick);
                this.zoomPictureBox_2_2.pictureBox1.DoubleClick += new EventHandler(zoomPictureBox_2_2_DoubleClick);
                this.zoomPictureBox_2_3.pictureBox1.DoubleClick += new EventHandler(zoomPictureBox_2_3_DoubleClick);

                this.zoomPictureBox_3_1.pictureBox1.DoubleClick += new EventHandler(zoomPictureBox_3_1_DoubleClick);
                this.zoomPictureBox_3_2.pictureBox1.DoubleClick += new EventHandler(zoomPictureBox_3_2_DoubleClick);
                this.zoomPictureBox_3_3.pictureBox1.DoubleClick += new EventHandler(zoomPictureBox_3_3_DoubleClick);

                this.zoomPictureBox_4_1.pictureBox1.DoubleClick += new EventHandler(zoomPictureBox_4_1_DoubleClick);
                this.zoomPictureBox_4_2.pictureBox1.DoubleClick += new EventHandler(zoomPictureBox_4_2_DoubleClick);
                this.zoomPictureBox_4_3.pictureBox1.DoubleClick += new EventHandler(zoomPictureBox_4_3_DoubleClick);

                this.zoomPictureBox_5_1.pictureBox1.DoubleClick += new EventHandler(zoomPictureBox_5_1_DoubleClick);
                this.zoomPictureBox_5_2.pictureBox1.DoubleClick += new EventHandler(zoomPictureBox_5_2_DoubleClick);
                this.zoomPictureBox_5_3.pictureBox1.DoubleClick += new EventHandler(zoomPictureBox_5_3_DoubleClick);

                SplitterDistance1 = 10;
                SplitterDistance2 = this.splitContainer1.SplitterDistance;

                if (PP.gISWebVersion == true)
                {
                    kdws = new JKZP.aitmskdws.aitmskdws();
                }

                toolStripComboBox_glld.Items.Clear();
                toolStripComboBox_glld.Items.AddRange(PP.gLuDuanList.ToArray());

                //DSSLoad();
            }
            catch { }
        }

        private void DSSLoad()
        {
            try
            {
                if (m_nSmartWndId != 0)
                {
                    m_nSmartWndId = this.axDPSDK_OCX1.DPSDK_CreateSmartWnd(0, 0, 100, 100);
                    m_nInit = -1;
                    if (m_nSmartWndId != 0)
                    {
                        this.toolStripStatusLabel_state.Text = "DPSDK_CreateSmartWnd()失败，错误码：" + m_nSmartWndId.ToString();
                        return;
                    }
                }

                if (m_nInit != 0)
                {
                    m_nLogin = -1;
                    m_nInit = this.axDPSDK_OCX1.DPSDK_SetWndCount((uint)m_nSmartWndId, 1);
                    if (m_nInit != 0)
                    {
                        this.toolStripStatusLabel_state.Text = "DPSDK_SetWndCount()失败，错误码：" + m_nInit.ToString();
                        return;
                    }
                }

                if (m_nLogin != 0)
                {
                    m_nLoadTree = -1;
                    m_nLogin = this.axDPSDK_OCX1.DPSDK_Login("172.20.160.9", 9000, "xzjl", "xzjl");
                    if (m_nLogin != 0)
                    {
                        this.toolStripStatusLabel_state.Text = "DPSDK_Login()失败，错误码：" + m_nLogin.ToString();
                        return;
                    }
                }

                if (m_nLoadTree != 0)
                {
                    m_nLoadTree = this.axDPSDK_OCX1.DPSDK_LoadDGroupInfo();
                    if (m_nLoadTree != 0)
                    {
                        this.toolStripStatusLabel_state.Text = "DPSDK_LoadDGroupInfo()失败，错误码：" + m_nLoadTree.ToString();
                        return;
                    }
                }

                if (m_TreeString == "")
                {
                    m_TreeString = this.axDPSDK_OCX1.DPSDK_GetDGroupStr();
                    //File.WriteAllText("C:\\Treenew.txt", m_TreeString);
                    if (m_TreeString != "")
                    {
                        XmlDocument doc = new XmlDocument();
                        doc.LoadXml(m_TreeString);

                        TreeNode troot = new TreeNode("root");
                        XmlNode departmentroot = doc.DocumentElement.SelectSingleNode("/Organization/Department");
                        XmlNode devicetroot = doc.DocumentElement.SelectSingleNode("/Organization/Devices");

                        LoadChannel(devicetroot);
                        AddNode(departmentroot, troot);

                        treeView2.Nodes.Clear();
                        treeView2.Nodes.Add(troot);
                    }
                }
            }
            catch (Exception er)
            {
                this.toolStripStatusLabel_state.Text = "DSSLoad()" + er.Message;
            }
        }

        private void DSSDispose()
        {
            try
            {
                this.axDPSDK_OCX1.DPSDK_StopRealplayByWndNo((uint)m_nSmartWndId, 0);
                this.axDPSDK_OCX1.DPSDK_Logout();
                this.axDPSDK_OCX1.Dispose();
            }
            catch { }
        }

        private void AddNode(XmlNode inXmlNode, TreeNode inTreeNode)
        {
            try
            {
                if (inXmlNode.Name == "Department")
                {
                    inTreeNode.Name = "Department";
                    inTreeNode.Text = inXmlNode.Attributes["name"].Value;
                    inTreeNode.Tag = inXmlNode.Attributes["coding"].Value;
                }
                else if (inXmlNode.Name == "Channel")
                {
                    inTreeNode.Name = "Channel";
                    inTreeNode.Tag = inXmlNode.Attributes["id"].Value;
                    inTreeNode.Text = ht_channel[inTreeNode.Tag].ToString();
                }

                if (inXmlNode.HasChildNodes)
                {
                    foreach (XmlNode xNode in inXmlNode.ChildNodes)
                    {
                        //不加载device层
                        if (xNode.Name == "Device") continue;

                        //不加载没有channel名称的层
                        if (xNode.Name == "Channel")
                        {
                            if (!ht_channel.Contains(xNode.Attributes["id"].Value)) continue;
                        }
                        TreeNode tNode = new TreeNode();
                        inTreeNode.Nodes.Add(tNode);
                        AddNode(xNode, tNode);
                    }
                }
            }
            catch { }
        }

        private void LoadChannel(XmlNode inXmlNode)
        {
            try
            {
                if (inXmlNode.Name == "Channel")
                {
                    string id = inXmlNode.Attributes["id"].Value;
                    string name = inXmlNode.Attributes["name"].Value;
                    ht_channel[id] = name;
                }

                if (inXmlNode.HasChildNodes)
                {
                    foreach (XmlNode xNode in inXmlNode.ChildNodes)
                    {
                        LoadChannel(xNode);
                    }
                }
            }
            catch { }
        }

        void comboBox_hpzl_MouseWheel(object sender, MouseEventArgs e)
        {
            try
            {
                if (e.Delta < 0)
                {
                    if (comboBox_hpzl.SelectedIndex < comboBox_hpzl.Items.Count - 1)
                    {
                        comboBox_hpzl.SelectedIndex++;
                    }
                }
                else if (e.Delta > 0)
                {
                    if (comboBox_hpzl.SelectedIndex > 0)
                    {
                        comboBox_hpzl.SelectedIndex--;
                    }
                }

            }
            catch {; }
        }

        void comboBox_wfxw_MouseWheel(object sender, MouseEventArgs e)
        {
            try
            {

                if (e.Delta < 0)
                {
                    if (comboBox_wfxw.SelectedIndex < comboBox_wfxw.Items.Count - 1)
                    {
                        comboBox_wfxw.SelectedIndex++;
                    }
                }
                else if (e.Delta > 0)
                {
                    if (comboBox_wfxw.SelectedIndex > 0)
                    {
                        comboBox_wfxw.SelectedIndex--;
                    }
                }

            }
            catch {; }
        }

        public void UpDateTree()
        {
            treeView1.Nodes.Clear();
            TreeNode root = new TreeNode();
            root.Text = "杰瑞监控抓拍系统";
            root.Tag = "root";
            root.Name = "root";
            root.ImageIndex = 0;
            root.SelectedImageIndex = 0;
            treeView1.Nodes.Add(root);

            if (PP.gLuDuanList != null)
            {
                foreach (string ld in PP.gLuDuanList)
                {
                    TreeNode ldnode = new TreeNode();
                    ldnode.Text = ld;
                    ldnode.Tag = ld;
                    ldnode.Name = "luduan";
                    ldnode.ImageIndex = 0;
                    ldnode.SelectedImageIndex = 0;
                    root.Nodes.Add(ldnode);
                }
            }
            


            if (PP.gRoadList != null)
            {
                foreach (PP.RoadParam road in PP.gRoadList)
                {
                    TreeNode roadnode = new TreeNode();
                    roadnode.Text = road.LKMC;
                    roadnode.Tag = road.LKID;
                    roadnode.Name = "road";
                    roadnode.ImageIndex = 1;
                    roadnode.SelectedImageIndex = 1;

                    bool found = false;
                    foreach (TreeNode ld in root.Nodes)
                    {
                        if (ld.Tag.ToString() == road.LuDuan)
                        {
                            found = true;
                            ld.Nodes.Add(roadnode);
                            break;
                        }
                    }

                    if (found == false)
                    {
                        root.Nodes.Add(roadnode);
                    }

                    if (road.JKCamList != null)
                    {
                        foreach (JKCamera cam in road.JKCamList)
                        {
                            TreeNode camnode = new TreeNode();
                            camnode.Text = cam.m_IP + "---" + cam.m_CameraName + "---" + cam.m_Type;
                            camnode.Tag = cam.m_IP;
                            camnode.Name = "camera";
                            camnode.SelectedImageIndex = 2;
                            camnode.ImageIndex = 2;
                            roadnode.Nodes.Add(camnode);
                        }
                    }
                }
            }
        }

        public void UpdateCombobox()
        {
            try
            {
                //违法行为
                string[] wfxwdm = File.ReadAllLines(PP.gWFXWDMFile);
                if (wfxwdm != null)
                {
                    comboBox_wfxw.Items.Clear();
                    comboBox_wfxw.Items.AddRange(wfxwdm);
                    comboBox_wfxw.SelectedIndex = 0;
                }

                string[] hpzl = File.ReadAllLines(PP.gHPZLFile);
                if (hpzl != null)
                {
                    comboBox_hpzl.Items.Clear();
                    comboBox_hpzl.Items.AddRange(hpzl);
                    comboBox_hpzl.SelectedIndex = 1;
                }
            }
            catch { }
        }

        public void SetSystemEnable(bool regstor, bool admin)
        {


            this.toolStripMenuItem_user.Enabled = regstor;
            this.toolStripMenuItem_yhgl.Enabled = regstor;
            this.toolStripMenuItem_changepassword.Enabled = regstor;
            this.toolStripMenuItem_param.Enabled = regstor;
            this.toolStripMenuItem_sys.Enabled = regstor;
            this.toolStripMenuItem_road.Enabled = regstor;
            this.toolStripMenuItem_camera.Enabled = regstor;
            this.toolStripMenuItem_wfxwdm.Enabled = regstor;
            this.ToolStripMenuItem_hpzl.Enabled = regstor;
            this.ToolStripMenuItem_upload.Enabled = regstor;
            this.toolStripMenuItem_tongji.Enabled = regstor;
            this.ToolStripMenuItem_virsion.Enabled = regstor;

            this.splitContainer1.Enabled = regstor;

            if (PP.gISWebVersion == false)
            {
                this.toolStripMenuItem_yhgl.Visible = false;
            }
            else
            {
                this.toolStripMenuItem_yhgl.Visible = admin;
            }
            this.toolStripMenuItem_param.Visible = admin;
            this.toolStripMenuItem_sys.Visible = admin;
            this.toolStripMenuItem_road.Visible = admin;
            this.toolStripMenuItem_camera.Visible = admin;
            this.toolStripMenuItem_wfxwdm.Visible = admin;
            this.ToolStripMenuItem_hpzl.Visible = admin;

            this.toolStripStatusLabel_state.Text = (regstor ? "软件已注册" : "软件未注册");

        }

        void m_systemTimer_Tick(object sender, EventArgs e)
        {
            this.toolStripStatusLabel_time.Text = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
        }

        private void Form_Main_FormClosed(object sender, FormClosedEventArgs e)
        {
            MyClose();
        }

        private void MyClose()
        {
            try
            {
                //关时间显示
                if (m_systemTimer != null)
                {
                    m_systemTimer.Stop();
                    m_systemTimer.Dispose();
                }

                if (PP.kdws != null) PP.kdws.Dispose();

                if (m_CurrentCam != null)
                {
                    if (m_CurrentCam != null) m_CurrentCam.ShutDown();
                }

                //SDK回收资源
                PP.HKSDKDispose();
                PP.DHSDKDispose();

                //DSS
                DSSDispose();
            }
            catch { }
        }

        //系统参数
        private void toolStripMenuItem_sys_Click(object sender, EventArgs e)
        {
            SysParamForm form = new SysParamForm();
            form.Owner = this;
            form.ShowDialog();
            form.Dispose();
        }

        //路口参数
        private void ToolStripMenuItem_road_Click(object sender, EventArgs e)
        {
            RoadForm form = new RoadForm();
            form.Owner = this;
            form.ShowDialog();
            form.Dispose();
        }

        //摄像机参数
        private void ToolStripMenuItem_camera_Click(object sender, EventArgs e)
        {
            CameraForm form = new CameraForm();
            form.Owner = this;
            form.ShowDialog();
            form.Dispose();
        }

        private void toolStripMenuItem_ip_Click(object sender, EventArgs e)
        {
            LocalIPForm form = new LocalIPForm();
            form.Owner = this;
            form.ShowDialog();
            form.Dispose();
        }

        //软件注册
        private void toolStripMenuItem_reg_Click(object sender, EventArgs e)
        {
            RegForm form_reg = new RegForm();
            form_reg.Owner = this;
            form_reg.ShowDialog();
            form_reg.Dispose();
            SetSystemEnable(true, PP.gUser.admin);
            //SetSystemEnable(PP.gSoftRegstor,PP.gUser.admin);
        }

        //版本说明
        private void ToolStripMenuItem_virsion_Click(object sender, EventArgs e)
        {
            virsion form_virsion = new virsion();
            form_virsion.Owner = this;
            form_virsion.ShowDialog();
            form_virsion.Dispose();
        }

        //退出
        private void ToolStripMenuItem_exit_Click(object sender, EventArgs e)
        {
            Close();
        }

        //保存预置点
        private void toolStripMenuItem_Set_Click(object sender, EventArgs e)
        {
            if (tabControl_tree.SelectedIndex == 0)
            {
                if (toolStripTextBox_name.Text == "")
                {
                    this.toolStripStatusLabel_state.Text = "保存预置点失败，助记名为空";
                    return;
                }
                if (m_CurrentCam == null)
                {
                    this.toolStripStatusLabel_state.Text = "保存预置点失败，摄像机未启动";
                    return;
                }

                int index = this.listBox_PreSetPoint.SelectedIndex;
                if (index > -1)
                {
                    if (m_CurrentCam.SavePreSetPoint(index + 1) == true)
                    {
                        string xpath = "descendant::camera[@ip='" + m_CurrentCam.m_IP + "']/PreSetPoint[@index='" + index.ToString() + "']";
                        if (PP.SetConfig(PP.gRoadFile, xpath, this.toolStripTextBox_name.Text, null, null) == true)
                        {
                            m_CurrentCam.m_PreSetPonitHelpName[index] = this.toolStripTextBox_name.Text;
                            this.listBox_PreSetPoint.Items.RemoveAt(index);
                            this.listBox_PreSetPoint.Items.Insert(index, (index + 1).ToString() + "---" + this.toolStripTextBox_name.Text);
                            if (PP.gISWebVersion == false)
                            {
                                this.toolStripStatusLabel_state.Text = "保存预置点成功";
                            }
                            else
                            {
                                if (PP.kdws.JKZP_EditYZD(m_CurrentCam.m_IP, index.ToString(), this.toolStripTextBox_name.Text) == true)
                                {
                                    this.toolStripStatusLabel_state.Text = "保存预置点成功";
                                }
                                else
                                {
                                    this.toolStripStatusLabel_state.Text = "保存预置点失败";
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                if (m_camid == "")
                {
                    this.toolStripStatusLabel_state.Text = "保存预置点失败，平台编号为空";
                    return;
                }

                int index = this.listBox_PreSetPoint.SelectedIndex+1;
                if (index > 0)
                {
                    int fff = this.axDPSDK_OCX1.DPSDK_PtzPrePointOperation(m_camid, index, "预置点" + index.ToString(), 2);
                    if (fff == 0)
                    {
                        this.toolStripStatusLabel_state.Text = "保存预置点成功";
                    }
                    else
                    {
                        this.toolStripStatusLabel_state.Text = "保存预置点失败 " + F.GetErrorText(fff) + " er=" + fff;
                    }
                }
            }
        }


        private void contextMenuStrip1_VisibleChanged(object sender, EventArgs e)
        {
            if (contextMenuStrip1.Visible)
            {
                toolStripTextBox_name.Text = "";
            }
        }

        private void treeView1_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                if (treeView1.SelectedNode == null) return;
                if (treeView1.SelectedNode.Name != "camera") return;
                if (I > 4) return;
                if (I < 0) return;
                string camip = treeView1.SelectedNode.Tag.ToString();

                //if ((zoomPictureBox_1_1.pictureBox1.Image != null) ||
                //    (zoomPictureBox_1_2.pictureBox1.Image != null) ||
                //    (zoomPictureBox_1_3.pictureBox1.Image != null))
                //{
                //    this.toolStripStatusLabel_state.Text = "抓拍组一有未保存的违法证据，请先保存后再切换抓拍点位";
                //    return;
                //}

                //if ((zoomPictureBox_2_1.pictureBox1.Image != null) ||
                //    (zoomPictureBox_2_2.pictureBox1.Image != null) ||
                //    (zoomPictureBox_2_3.pictureBox1.Image != null))
                //{
                //    this.toolStripStatusLabel_state.Text = "抓拍组二有未保存的违法证据，请先保存后再切换抓拍点位";
                //    return;
                //}

                //if ((zoomPictureBox_3_1.pictureBox1.Image != null) ||
                //    (zoomPictureBox_3_2.pictureBox1.Image != null) ||
                //    (zoomPictureBox_3_3.pictureBox1.Image != null))
                //{
                //    this.toolStripStatusLabel_state.Text = "抓拍组三有未保存的违法证据，请先保存后再切换抓拍点位";
                //    return;
                //}

                //if ((zoomPictureBox_4_1.pictureBox1.Image != null) ||
                //    (zoomPictureBox_4_2.pictureBox1.Image != null) ||
                //    (zoomPictureBox_4_3.pictureBox1.Image != null))
                //{
                //    this.toolStripStatusLabel_state.Text = "抓拍组四有未保存的违法证据，请先保存后再切换抓拍点位";
                //    return;
                //}

                //if ((zoomPictureBox_5_1.pictureBox1.Image != null) ||
                //    (zoomPictureBox_5_2.pictureBox1.Image != null) ||
                //    (zoomPictureBox_5_3.pictureBox1.Image != null))
                //{
                //    this.toolStripStatusLabel_state.Text = "抓拍组五有未保存的违法证据，请先保存后再切换抓拍点位";
                //    return;
                //}

                if ((m_CurrentCam != null) && (camip == m_CurrentCam.m_IP) && (m_CurrentCam.m_CamIsOpen)) return;

                if (m_CurrentCam != null)
                {
                    m_CurrentCam.ShutDown();
                    this.panel_play.Invalidate();
                }
                m_CurrentCam = PP.FindCamByIP(camip);
                if (m_CurrentCam != null)
                {
                    m_CurrentCam.Play(panel_play.Handle);
                    this.listBox_PreSetPoint.Items.Clear();
                    if ((m_CurrentCam.m_PreSetPonitHelpName != null) && (m_CurrentCam.m_PreSetPonitHelpName.Count > 0))
                    {
                        for (int i = 0; i < m_CurrentCam.m_PreSetPonitHelpName.Count; i++)
                        {
                            this.listBox_PreSetPoint.Items.Add((i + 1).ToString() + "---" + m_CurrentCam.m_PreSetPonitHelpName[i]);
                        }
                    }
                    m_CurrentCam.CheckTime();
                }
            }
            catch { }
        }

        private void button_speeddown_Click(object sender, EventArgs e)
        {
            if (speed > cMinSpeed) speed--;
            this.toolStripStatusLabel_state.Text = "球机速度 = " + speed.ToString();
        }

        private void button_speedup_Click(object sender, EventArgs e)
        {
            if (speed < cMaxSpeed) speed++;
            this.toolStripStatusLabel_state.Text = "球机速度 = " + speed.ToString();
        }

        private void button_center_Click(object sender, EventArgs e)
        {
            if (tabControl_tree.SelectedIndex == 0)
            {
                if (m_CurrentCam != null) m_CurrentCam.CallPreSetPoint(1);
            }
            else
            {
                if (m_camid != "")
                {
                    axDPSDK_OCX1.DPSDK_PtzPrePointOperation(m_camid, 1, "预置点1", 1);
                }
            }
        }

        private void button_up_MouseDown(object sender, MouseEventArgs e)
        {
            if (tabControl_tree.SelectedIndex == 0)
            {
                if (m_CurrentCam != null) m_CurrentCam.Up(speed, false);
            }
            else
            {
                if (m_camid != "")
                {
                    axDPSDK_OCX1.DPSDK_PtzDirection(m_camid, 1, speed, false);
                    
                }
            }
        }

        private void button_up_MouseUp(object sender, MouseEventArgs e)
        {
            if (tabControl_tree.SelectedIndex == 0)
            {
                if (m_CurrentCam != null) m_CurrentCam.Up(speed, true);
            }
            else
            {
                if (m_camid != "")
                {
                     axDPSDK_OCX1.DPSDK_PtzDirection(m_camid, 1, speed, true);
                    
                }
            }
        }

        private void button_down_MouseDown(object sender, MouseEventArgs e)
        {
            if (tabControl_tree.SelectedIndex == 0)
            {
                if (m_CurrentCam != null) m_CurrentCam.Down(speed, false);
            }
            else
            {
                if (m_camid != "")
                {
                    axDPSDK_OCX1.DPSDK_PtzDirection(m_camid, 2, speed, false);
                    
                }
            }
        }

        private void button_down_MouseUp(object sender, MouseEventArgs e)
        {
            if (tabControl_tree.SelectedIndex == 0)
            {
                if (m_CurrentCam != null) m_CurrentCam.Down(speed, true);
            }
            else
            {
                if (m_camid != "")
                {
                     axDPSDK_OCX1.DPSDK_PtzDirection(m_camid, 2, speed, true);
                    
                }
            }
        }

        private void button_left_MouseDown(object sender, MouseEventArgs e)
        {
            if (tabControl_tree.SelectedIndex == 0)
            {
                if (m_CurrentCam != null) m_CurrentCam.Left(speed, false);
            }
            else
            {
                if (m_camid != "")
                {
                     axDPSDK_OCX1.DPSDK_PtzDirection(m_camid, 3, speed, false);
                    
                }
            }
        }

        private void button_left_MouseUp(object sender, MouseEventArgs e)
        {
            if (tabControl_tree.SelectedIndex == 0)
            {
                if (m_CurrentCam != null) m_CurrentCam.Left(speed, true);
            }
            else
            {
                if (m_camid != "")
                {
                     axDPSDK_OCX1.DPSDK_PtzDirection(m_camid, 3, speed, true);
                    
                }
            }
        }

        private void button_right_MouseDown(object sender, MouseEventArgs e)
        {
            if (tabControl_tree.SelectedIndex == 0)
            {
                if (m_CurrentCam != null) m_CurrentCam.Right(speed, false);
            }
            else
            {
                if (m_camid != "")
                {
                     axDPSDK_OCX1.DPSDK_PtzDirection(m_camid, 4, speed, false);
                    
                }
            }
        }

        private void button_right_MouseUp(object sender, MouseEventArgs e)
        {
            if (tabControl_tree.SelectedIndex == 0)
            {
                if (m_CurrentCam != null) m_CurrentCam.Right(speed, true);
            }
            else
            {
                if (m_camid != "")
                {
                     axDPSDK_OCX1.DPSDK_PtzDirection(m_camid, 4, speed, true);
                   
                }
            }
        }

        private void button_near_MouseDown(object sender, MouseEventArgs e)
        {
            if (tabControl_tree.SelectedIndex == 0)
            {
                if (m_CurrentCam != null) m_CurrentCam.ZoomIn(speed, false);
            }
            else
            {
                if (m_camid != "")
                {
                     axDPSDK_OCX1.DPSDK_PtzCameraOperation(m_camid, 0, speed, false);
                    
                }
            }
        }

        private void button_near_MouseUp(object sender, MouseEventArgs e)
        {
            if (tabControl_tree.SelectedIndex == 0)
            {
                if (m_CurrentCam != null) m_CurrentCam.ZoomIn(speed, true);
            }
            else
            {
                if (m_camid != "")
                {
                     axDPSDK_OCX1.DPSDK_PtzCameraOperation(m_camid, 0, speed, true);
                    
                }
            }
        }

        private void button_far_MouseDown(object sender, MouseEventArgs e)
        {
            if (tabControl_tree.SelectedIndex == 0)
            {
                if (m_CurrentCam != null) m_CurrentCam.ZoomOut(speed, false);
            }
            else
            {
                if (m_camid != "")
                {
                     axDPSDK_OCX1.DPSDK_PtzCameraOperation(m_camid, 3, speed, false);
                    
                }
            }
        }

        private void button_far_MouseUp(object sender, MouseEventArgs e)
        {
            if (tabControl_tree.SelectedIndex == 0)
            {
                if (m_CurrentCam != null) m_CurrentCam.Down(speed, true);
            }
            else
            {
                if (m_camid != "")
                {
                     axDPSDK_OCX1.DPSDK_PtzCameraOperation(m_camid, 3, speed, true);
                    
                }
            }
        }

        //调用预置点
        private void listBox_PreSetPoint_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (tabControl_tree.SelectedIndex == 0)
            {
                if (this.listBox_PreSetPoint.SelectedIndex > -1)
                {
                    if (m_CurrentCam != null) m_CurrentCam.CallPreSetPoint(this.listBox_PreSetPoint.SelectedIndex + 1);
                }
            }
            else
            {
                if (this.listBox_PreSetPoint.SelectedIndex > -1)
                {
                    if (m_camid != "")
                    {
                        int yzd = this.listBox_PreSetPoint.SelectedIndex + 1;
                        axDPSDK_OCX1.DPSDK_PtzPrePointOperation(m_camid, yzd, "预置点"+ yzd.ToString(), 1);
                    }
                }
            }
        }

        private void button_capture_Click(object sender, EventArgs e)
        {
            //MessageBox.Show(Convert.ToString(tabControl2.SelectedIndex));
            indexIP[tabControl2.SelectedIndex] = m_CurrentCam.m_IP;
            if (this.tabControl_tree.SelectedIndex == 0)
            {
                try
                {
                    if ((I < 0) || (I > 4)) return;
                    if (m_CurrentCam != null)
                    {
                        if (index[I] == 0)
                        {
                            a_CurrentCam[I] = m_CurrentCam;
                        }

                        if (index[I] == 3) return;//index[I] = 0;
                        index[I]++;
                        //DateTime time = DateTime.Now.Subtract(new TimeSpan(0,0,0,1));//设备显示的叠加时间比获取到的时间少1秒
                        if (index[I] == 1)
                        {
                            m_WFSJ[I] = DateTime.Now;//张家界从第二张获取违法时间，连云港，睢宁从第一张获取时间
                            //if (index == 1) m_CurrentCam.m_WFSJ = m_CurrentCam.GetDeviceTime();//从设备获取时间
                        }
                        if (m_CurrentCam.CaptureOnePic((I + 1).ToString(), index[I].ToString(), m_CurrentCam) == true)
                        {
                            if (File.Exists(m_CurrentCam.m_TempPicName))
                            {
                                Control[] cc = this.Controls.Find("zoomPictureBox_" + (I + 1).ToString() + "_" + index[I].ToString(), true);
                                if ((cc != null) && (cc.Length > 0))
                                {
                                    ZoomPictureBox box = (cc[0] as ZoomPictureBox);
                                    box.pictureBox1.LoadAsync(m_CurrentCam.m_TempPicName);
                                }
                            }
                        }
                    }
                }
                catch { }
            }
            else
            {
                try
                {
                    if ((I < 0) || (I > 4)) return;
                    if (index[I] == 3) return;
                    index[I]++;
                    if (index[I] == 1)
                    {
                        m_WFSJ[I] = DateTime.Now;//张家界从第二张获取违法时间，连云港，睢宁从第一张获取时间
                    }
                    if (m_camid != "")
                    {
                        string group = (I + 1).ToString();
                        string thisindex = index[I].ToString();
                        string filename = PP.gTempFolder + group + "_" + thisindex + ".jpg";
                        if (0 == this.axDPSDK_OCX1.DPSDK_CapturePictureByWndNo((uint)m_nSmartWndId, 0, filename))
                        {
                            if (File.Exists(filename))
                            {
                                Control[] cc = this.Controls.Find("zoomPictureBox_" + group + "_" + thisindex, true);
                                if ((cc != null) && (cc.Length > 0))
                                {
                                    ZoomPictureBox box = (cc[0] as ZoomPictureBox);
                                    box.pictureBox1.LoadAsync(filename);
                                }
                            }
                        }
                    }
                }
                catch { }
            }
        }

        private void button_clear_Click(object sender, EventArgs e)
        {
            try
            {
                if ((I < 0) || (I > 4)) return;

                if (I == 0)
                {
                    index[0] = 0;
                    zoomPictureBox_1_1.zoomRequired = false;
                    zoomPictureBox_1_1.pictureBox1.Image = null;
                    zoomPictureBox_1_2.zoomRequired = false;
                    zoomPictureBox_1_2.pictureBox1.Image = null;
                    zoomPictureBox_1_3.zoomRequired = false;
                    zoomPictureBox_1_3.pictureBox1.Image = null;
                    this.textBox_hphm.Text = PP.gDefaultHPHM;
                    File.Delete(PP.gTempFolder + "1_1.jpg");
                    File.Delete(PP.gTempFolder + "1_2.jpg");
                    File.Delete(PP.gTempFolder + "1_3.jpg");
                    File.Delete(PP.gTempFolder + "1_1.bmp");
                    File.Delete(PP.gTempFolder + "1_2.bmp");
                    File.Delete(PP.gTempFolder + "1_3.bmp");
                }

                if (I == 1)
                {
                    index[1] = 0;
                    zoomPictureBox_2_1.zoomRequired = false;
                    zoomPictureBox_2_1.pictureBox1.Image = null;
                    zoomPictureBox_2_2.zoomRequired = false;
                    zoomPictureBox_2_2.pictureBox1.Image = null;
                    zoomPictureBox_2_3.zoomRequired = false;
                    zoomPictureBox_2_3.pictureBox1.Image = null;
                    this.textBox_hphm.Text = PP.gDefaultHPHM;
                    File.Delete(PP.gTempFolder + "2_1.jpg");
                    File.Delete(PP.gTempFolder + "2_2.jpg");
                    File.Delete(PP.gTempFolder + "2_3.jpg");
                    File.Delete(PP.gTempFolder + "2_1.bmp");
                    File.Delete(PP.gTempFolder + "2_2.bmp");
                    File.Delete(PP.gTempFolder + "2_3.bmp");
                }

                if (I == 2)
                {
                    index[2] = 0;
                    zoomPictureBox_3_1.zoomRequired = false;
                    zoomPictureBox_3_1.pictureBox1.Image = null;
                    zoomPictureBox_3_2.zoomRequired = false;
                    zoomPictureBox_3_2.pictureBox1.Image = null;
                    zoomPictureBox_3_3.zoomRequired = false;
                    zoomPictureBox_3_3.pictureBox1.Image = null;
                    this.textBox_hphm.Text = PP.gDefaultHPHM;
                    File.Delete(PP.gTempFolder + "3_1.jpg");
                    File.Delete(PP.gTempFolder + "3_2.jpg");
                    File.Delete(PP.gTempFolder + "3_3.jpg");
                    File.Delete(PP.gTempFolder + "3_1.bmp");
                    File.Delete(PP.gTempFolder + "3_2.bmp");
                    File.Delete(PP.gTempFolder + "3_3.bmp");
                }

                if (I == 3)
                {
                    index[3] = 0;
                    zoomPictureBox_4_1.zoomRequired = false;
                    zoomPictureBox_4_1.pictureBox1.Image = null;
                    zoomPictureBox_4_2.zoomRequired = false;
                    zoomPictureBox_4_2.pictureBox1.Image = null;
                    zoomPictureBox_4_3.zoomRequired = false;
                    zoomPictureBox_4_3.pictureBox1.Image = null;
                    this.textBox_hphm.Text = PP.gDefaultHPHM;
                    File.Delete(PP.gTempFolder + "4_1.jpg");
                    File.Delete(PP.gTempFolder + "4_2.jpg");
                    File.Delete(PP.gTempFolder + "4_3.jpg");
                    File.Delete(PP.gTempFolder + "4_1.bmp");
                    File.Delete(PP.gTempFolder + "4_2.bmp");
                    File.Delete(PP.gTempFolder + "4_3.bmp");
                }

                if (I == 4)
                {
                    index[4] = 0;
                    zoomPictureBox_5_1.zoomRequired = false;
                    zoomPictureBox_5_1.pictureBox1.Image = null;
                    zoomPictureBox_5_2.zoomRequired = false;
                    zoomPictureBox_5_2.pictureBox1.Image = null;
                    zoomPictureBox_5_3.zoomRequired = false;
                    zoomPictureBox_5_3.pictureBox1.Image = null;
                    this.textBox_hphm.Text = PP.gDefaultHPHM;
                    File.Delete(PP.gTempFolder + "5_1.jpg");
                    File.Delete(PP.gTempFolder + "5_2.jpg");
                    File.Delete(PP.gTempFolder + "5_3.jpg");
                    File.Delete(PP.gTempFolder + "5_1.bmp");
                    File.Delete(PP.gTempFolder + "5_2.bmp");
                    File.Delete(PP.gTempFolder + "5_3.bmp");
                }
            }
            catch { }
        }

        private void button_save_Click(object sender, EventArgs e)
        {
            try
            {
                //if (this.textBox_hphm.Text.Length <7)
                //{
                //    this.toolStripStatusLabel_state.Text = "保存失败,号牌号码长度不对";
                //    return;
                //}
                if ((I > 4) || (I < 0)) return;

                if ((I == 0) &&
                    ((zoomPictureBox_1_1.pictureBox1.Image == null) ||
                    (zoomPictureBox_1_2.pictureBox1.Image == null) ||
                    (zoomPictureBox_1_3.pictureBox1.Image == null)))
                {
                    this.toolStripStatusLabel_state.Text = "保存失败,组一违法证据抓拍3张";
                    return;
                }

                if ((I == 1) &&
                    ((zoomPictureBox_2_1.pictureBox1.Image == null) ||
                    (zoomPictureBox_2_2.pictureBox1.Image == null) ||
                    (zoomPictureBox_2_3.pictureBox1.Image == null)))
                {
                    this.toolStripStatusLabel_state.Text = "保存失败,组二违法证据抓拍3张";
                    return;
                }

                if ((I == 2) &&
                    ((zoomPictureBox_3_1.pictureBox1.Image == null) ||
                    (zoomPictureBox_3_2.pictureBox1.Image == null) ||
                    (zoomPictureBox_3_3.pictureBox1.Image == null)))
                {
                    this.toolStripStatusLabel_state.Text = "保存失败,组三违法证据抓拍3张";
                    return;
                }

                if ((I == 3) &&
                    ((zoomPictureBox_4_1.pictureBox1.Image == null) ||
                    (zoomPictureBox_4_2.pictureBox1.Image == null) ||
                    (zoomPictureBox_4_3.pictureBox1.Image == null)))
                {
                    this.toolStripStatusLabel_state.Text = "保存失败,组四违法证据抓拍3张";
                    return;
                }

                if ((I == 4) &&
                    ((zoomPictureBox_5_1.pictureBox1.Image == null) ||
                    (zoomPictureBox_5_2.pictureBox1.Image == null) ||
                    (zoomPictureBox_5_3.pictureBox1.Image == null)))
                {
                    this.toolStripStatusLabel_state.Text = "保存失败,组五违法证据抓拍3张";
                    return;
                }

                if (tabControl_tree.SelectedIndex == 0)
                {
                    

                    if (m_CurrentCam != null)
                    {
                        m_CurrentCam.m_WFSJ = m_WFSJ[I];
                        m_CurrentCam.m_HPHM = this.textBox_hphm.Text;
                        string wfxw = this.comboBox_wfxw.Text.Trim();
                        m_CurrentCam.m_WFXWDM = wfxw.Split('-')[0];
                        string hpzl = this.comboBox_hpzl.Text.Trim();
                        m_CurrentCam.m_ManuelHPZL = hpzl.Split('-')[0];

                        if (m_CurrentCam.SaveOneGroup((I + 1).ToString()) == true)
                        {
                            this.toolStripStatusLabel_state.Text = "保存成功";
                            button_clear_Click(sender, e);

                            this.dataGridView1.Rows.Add(new object[]
                            { m_CurrentCam.m_HPHM,
                            m_CurrentCam.m_WFSJ.ToString("yyyy-MM-dd HH:mm:ss"),
                            m_CurrentCam.m_RoadName,
                            m_CurrentCam.m_WFXWDM,
                            m_CurrentCam.m_FileName1,
                            m_CurrentCam.m_FileName2,
                            m_CurrentCam.m_FileName3
                            });
                            m_CurrentCam.m_FileName1 = "";
                            m_CurrentCam.m_FileName2 = "";
                            m_CurrentCam.m_FileName3 = "";
                        }
                    }
                }
                else
                {
                    if (m_camid!= "")
                    {
                        string wfdd = "";
                        string camname = "";
                        string roadname = "";

                        if(PP.gDPSDK_WFDD.Contains(m_camid)==false)
                        {
                            this.toolStripStatusLabel_state.Text = "保存失败，没有启用该流媒体设备，请联系管理员添加地点代码";
                            return;
                        }

                        wfdd = PP.gDPSDK_WFDD[m_camid].ToString().Replace("*", "-");
                        camname = ht_channel[m_camid].ToString().Replace("*", "-");
                        roadname = camname;

                        string wfxw = this.comboBox_wfxw.Text.Trim().Split('-')[0];
                        string hpzl = this.comboBox_hpzl.Text.Trim().Split('-')[0];

                        if (DPSDK_SaveOneGroup((I + 1).ToString(),wfdd,roadname,camname,
                            m_WFSJ[I],this.textBox_hphm.Text,
                            wfxw, hpzl) == true)
                        {
                            this.toolStripStatusLabel_state.Text = "保存成功";
                            button_clear_Click(sender, e);

                            this.dataGridView1.Rows.Add(new object[]
                            {this.textBox_hphm.Text,
                            m_WFSJ[I].ToString("yyyy-MM-dd HH:mm:ss"),
                            roadname,
                            wfxw,
                            FileName1,
                            FileName2,
                            FileName3
                            });
                            FileName1 = "";
                            FileName2 = "";
                            FileName3 = "";
                        }
                    }
                }
            }
            catch { }
        }

        private bool DPSDK_SaveOneGroup(string group,string wfdd,string roadname,string camname, DateTime wfsj, string hphm, string wfxwdm, string hpzl)
        {
            bool ans = false;
            try
            {
                if (PP.gJKRecordEnable == true)
                {
                    return (DPSDK_SaveOnePic(group, "1",wfdd, roadname, camname,wfsj, hphm,wfxwdm,hpzl) &&
                        DPSDK_SaveOnePic(group, "2",wfdd, roadname, camname, wfsj, hphm, wfxwdm, hpzl) &&
                        DPSDK_SaveOnePic(group, "3",wfdd, roadname, camname, wfsj, hphm, wfxwdm, hpzl) &&
                        DPSDK_SaveOneRecord(group,wfdd, roadname, camname, wfsj, hphm, wfxwdm, hpzl));
                }
                else
                {
                    return (DPSDK_SaveOnePic(group, "1",wfdd, roadname, camname, wfsj, hphm, wfxwdm, hpzl) &&
                        DPSDK_SaveOnePic(group, "2",wfdd, roadname, camname, wfsj, hphm, wfxwdm, hpzl) &&
                        DPSDK_SaveOnePic(group, "3",wfdd, roadname, camname, wfsj, hphm, wfxwdm, hpzl));
                }

            }
            catch
            {
                ans = false;
            }
            return ans;
        }


        private bool DPSDK_SaveOnePic(string group,string index,string wfdd,string roadname, string camname, DateTime wfsj, string hphm, string wfxwdm, string hpzl)
        {
            bool ans = false;
            string splitor = "\\";
            try
            {
                string jpgfile = PP.gTempFolder + group + "_" + index + ".jpg";
                //转换bmp为jpg
                byte[] pic = File.ReadAllBytes(jpgfile);
                byte[] picWithTail = null;

                //计算保存路径
                string jkPicName = "0011-" + wfsj.ToString("yyyyMMddHHmmss-fff") + "-3-" + index + ".jpg";
                string jkSubPath = "";
                if (PP.gJKSaveBySubFolder)
                {
                    jkSubPath = "\\" + wfsj.ToString("yyyyMMdd") + "\\" + camname;
                }
                string jkPath = PP.gJKSavePath + jkSubPath;
                if (!Directory.Exists(jkPath)) Directory.CreateDirectory(jkPath);

                //准备数据
                if (PP.gJARITailEnable == true)
                {
                    PP.structJariPicInfo info = new PP.structJariPicInfo();
                    info.m_Info1 = wfdd;//DPSDK_WFDD
                    info.m_Info2 = index;
                    info.m_Info3 = "0";
                    info.m_Info4 = hphm;
                    info.m_Info5 = "0";
                    info.m_Info6 = "0";
                    info.m_Info7 = "0";
                    info.m_Info8 = "0";
                    info.m_Info9 = "1";
                    info.m_Info10 = "3";
                    info.m_Info11 = "";
                    info.m_Info12 = roadname;
                    info.m_Info13 = "";
                    info.m_Info14 = PP.gUser.username;
                    info.m_Info15 = "";
                    info.m_Info16 = "";
                    info.m_Info17 = "00";//DPSDK_WFDD
                    info.m_Info18 = wfsj.ToString("yyyy-MM-dd HH:mm:ss");
                    info.m_Info19 = "1";
                    info.m_Info20 = "车道1";
                    info.m_Info21 = "";
                    info.m_Info22 = "";
                    info.m_Info23 = "";
                    info.m_Info24 = "";

                    //叠加尾部信息
                    picWithTail = PP.AddTailToPic(info, pic);
                    //保存
                    File.WriteAllBytes(jkPath + splitor + jkPicName, picWithTail);
                }
                else
                {
                    //保存
                    File.WriteAllBytes(jkPath + splitor + jkPicName, pic);
                }


                //生成3张图片名，辅助生成图片记录
                if (index == "1")
                {
                    FileName1 = jkPath + splitor + jkPicName;
                }
                else if (index == "2")
                {
                    FileName2 = jkPath + splitor + jkPicName;
                }
                else if (index == "3")
                {
                    FileName3 = jkPath + splitor + jkPicName;
                }
                else { }


                if (File.Exists(jkPath + splitor + jkPicName))
                {
                    ans = true;
                    File.Delete(jpgfile);
                }
            }
            catch
            {
                ans = false;
            }
            return ans;
        }

        private bool DPSDK_SaveOneRecord(string group,string wfdd,string roadname, string camname, DateTime wfsj, string hphm, string wfxwdm, string hpzl)
        {
            bool ans = false;
            try
            {
                if ((FileName1 != "") && (FileName2 != "") && (FileName3 != ""))
                {
                    RecordParam record = new RecordParam();
                    record.SnapCount = "3";
                    record.picJionMode = "0";
                    record.recordType = "12";
                    record.Company = "JARI";
                    record.captureDevice = "9";
                    record.deviceID = "12";
                    record.captureUser = PP.gUser.username;
                    record.WFXWDM = wfxwdm;
                    record.GBDM = wfdd;
                    record.BMBH = "";
                    record.roadid = "00";
                    record.roadname = camname;//record.roadname = m_RoadName;睢宁抓拍用球机名称保存文件夹，用于拷贝文件后AutoInsert扫描上传
                    record.directionID = "1";
                    record.CD = "1";
                    record.JGSJ = wfsj.ToString("yyyyMMddHHmmssfff");
                    record.RedLightBeginTime = "";
                    record.RedLightDuration = "0";
                    record.plateType = hpzl;//借用platetype传输ManuelCarType
                    record.ManuelCarType = hpzl;
                    record.plateColor = "";
                    record.HPHM = hphm;
                    record.bodyColor = "0";
                    record.speedLimit = "0";
                    record.speed = "0";

                    record.PIC1 = FileName1;
                    record.PIC2 = FileName2;
                    record.PIC3 = FileName3;
                    record.PIC4 = "";
                    record.PICZoom = "";
                    record.PICPlate = "";

                    record.Save(PP.gJKRecordPath);


                    return true;
                }

            }
            catch
            {
                ans = false;
            }
            return ans;
        }

        private void panel_play_MouseDown(object sender, MouseEventArgs e)
        {
            pointStart.X = e.X;
            pointStart.Y = e.Y;
            m_FlagRect = true;
        }

        private void panel_play_MouseUp(object sender, MouseEventArgs e)
        {
            pointEnd.X = e.X;
            pointEnd.Y = e.Y;
            if (m_FlagRect == true)
            {
                m_FlagRect = false;
                Rectangle WinRect = new Rectangle(this.panel_play.Location, this.panel_play.Size);
                if (m_CurrentCam != null) m_CurrentCam.PTZ3D(WinRect, pointStart, pointEnd);
            }
        }

        private void panel_play_MouseMove(object sender, MouseEventArgs e)
        {
            Rectangle rt = new Rectangle(this.panel_play.Location, this.panel_play.Size);
            int x = e.X;
            int y = e.Y;
            x = x > rt.Right ? rt.Right : x;
            x = x < rt.Left ? rt.Left : x;
            y = y > rt.Bottom ? rt.Bottom : y;
            y = y < rt.Top ? rt.Top : y;
            pointEnd.X = x;
            pointEnd.Y = y;
        }

        private void zoomPictureBox_1_1_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                index[0] = 0;
                zoomPictureBox_1_1.zoomRequired = false;
                zoomPictureBox_1_1.pictureBox1.Image = null;
                File.Delete(PP.gTempFolder + "1_1.jpg");
                File.Delete(PP.gTempFolder + "1_1.bmp");
            }
            catch { }
        }

        private void zoomPictureBox_1_2_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                index[0] = 1;
                zoomPictureBox_1_2.zoomRequired = false;
                zoomPictureBox_1_2.pictureBox1.Image = null;
                File.Delete(PP.gTempFolder + "1_2.jpg");
                File.Delete(PP.gTempFolder + "1_2.bmp");
            }
            catch { }
        }

        private void zoomPictureBox_1_3_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                index[0] = 2;
                zoomPictureBox_1_3.zoomRequired = false;
                zoomPictureBox_1_3.pictureBox1.Image = null;
                File.Delete(PP.gTempFolder + "1_3.jpg");
                File.Delete(PP.gTempFolder + "1_3.bmp");
            }
            catch { }
        }

        private void zoomPictureBox_2_1_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                index[1] = 0;
                zoomPictureBox_2_1.zoomRequired = false;
                zoomPictureBox_2_1.pictureBox1.Image = null;
                File.Delete(PP.gTempFolder + "2_1.jpg");
                File.Delete(PP.gTempFolder + "2_1.bmp");
            }
            catch { }
        }

        private void zoomPictureBox_2_2_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                index[1] = 1;
                zoomPictureBox_2_2.zoomRequired = false;
                zoomPictureBox_2_2.pictureBox1.Image = null;
                File.Delete(PP.gTempFolder + "2_2.jpg");
                File.Delete(PP.gTempFolder + "2_2.bmp");
            }
            catch { }
        }

        private void zoomPictureBox_2_3_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                index[1] = 2;
                zoomPictureBox_2_3.zoomRequired = false;
                zoomPictureBox_2_3.pictureBox1.Image = null;
                File.Delete(PP.gTempFolder + "2_3.jpg");
                File.Delete(PP.gTempFolder + "2_3.bmp");
            }
            catch { }
        }


        private void zoomPictureBox_3_1_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                index[2] = 0;
                zoomPictureBox_3_1.zoomRequired = false;
                zoomPictureBox_3_1.pictureBox1.Image = null;
                File.Delete(PP.gTempFolder + "3_1.jpg");
                File.Delete(PP.gTempFolder + "3_1.bmp");
            }
            catch { }
        }

        private void zoomPictureBox_3_2_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                index[2] = 1;
                zoomPictureBox_3_2.zoomRequired = false;
                zoomPictureBox_3_2.pictureBox1.Image = null;
                File.Delete(PP.gTempFolder + "3_2.jpg");
                File.Delete(PP.gTempFolder + "3_2.bmp");
            }
            catch { }
        }

        private void zoomPictureBox_3_3_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                index[2] = 2;
                zoomPictureBox_3_3.zoomRequired = false;
                zoomPictureBox_3_3.pictureBox1.Image = null;
                File.Delete(PP.gTempFolder + "3_3.jpg");
                File.Delete(PP.gTempFolder + "3_3.bmp");
            }
            catch { }
        }

        private void zoomPictureBox_4_1_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                index[3] = 0;
                zoomPictureBox_4_1.zoomRequired = false;
                zoomPictureBox_4_1.pictureBox1.Image = null;
                File.Delete(PP.gTempFolder + "4_1.jpg");
                File.Delete(PP.gTempFolder + "4_1.bmp");
            }
            catch { }
        }

        private void zoomPictureBox_4_2_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                index[3] = 1;
                zoomPictureBox_4_2.zoomRequired = false;
                zoomPictureBox_4_2.pictureBox1.Image = null;
                File.Delete(PP.gTempFolder + "4_2.jpg");
                File.Delete(PP.gTempFolder + "4_2.bmp");
            }
            catch { }
        }

        private void zoomPictureBox_4_3_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                index[3] = 2;
                zoomPictureBox_4_3.zoomRequired = false;
                zoomPictureBox_4_3.pictureBox1.Image = null;
                File.Delete(PP.gTempFolder + "4_3.jpg");
                File.Delete(PP.gTempFolder + "4_3.bmp");
            }
            catch { }
        }

        private void zoomPictureBox_5_1_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                index[4] = 0;
                zoomPictureBox_5_1.zoomRequired = false;
                zoomPictureBox_5_1.pictureBox1.Image = null;
                File.Delete(PP.gTempFolder + "5_1.jpg");
                File.Delete(PP.gTempFolder + "5_1.bmp");
            }
            catch { }
        }

        private void zoomPictureBox_5_2_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                index[4] = 1;
                zoomPictureBox_5_2.zoomRequired = false;
                zoomPictureBox_5_2.pictureBox1.Image = null;
                File.Delete(PP.gTempFolder + "5_2.jpg");
                File.Delete(PP.gTempFolder + "5_2.bmp");
            }
            catch { }
        }

        private void zoomPictureBox_5_3_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                index[4] = 2;
                zoomPictureBox_5_3.zoomRequired = false;
                zoomPictureBox_5_3.pictureBox1.Image = null;
                File.Delete(PP.gTempFolder + "5_3.jpg");
                File.Delete(PP.gTempFolder + "5_3.bmp");
            }
            catch { }
        }
        //键盘处理
        private void Form_Main_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = false;
        }

        private void Form_Main_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                switch (e.KeyValue)
                {
                    case 49:
                        if (e.Control) tabControl2.SelectedIndex = 0;
                        break;
                    case 50:
                        if (e.Control) tabControl2.SelectedIndex = 1;
                        break;
                    case 51:
                        if (e.Control) tabControl2.SelectedIndex = 2;
                        break;
                    case 52:
                        if (e.Control) tabControl2.SelectedIndex = 3;
                        break;
                    case 53:
                        if (e.Control) tabControl2.SelectedIndex = 4;
                        break;
                    case 54:
                        if (e.Control) tabControl2.SelectedIndex = 5;
                        break;
                    case 38://上
                        button_up_MouseDown(null, null);
                        e.Handled = true;
                        break;
                    case 40://下
                        button_down_MouseDown(null, null);
                        e.Handled = true;
                        break;
                    case 37://左
                        button_left_MouseDown(null, null);
                        e.Handled = true;
                        break;
                    case 39://右
                        button_right_MouseDown(null, null);
                        e.Handled = true;
                        break;
                    case 186://拉近
                        button_near_MouseDown(null, null);
                        e.Handled = true;
                        break;
                    case 222://拉远
                        button_far_MouseDown(null, null);
                        e.Handled = true;
                        break;
                    case 187://速度+
                        button_speedup_Click(null, null);
                        e.Handled = true;
                        break;
                    case 189://速度-
                        button_speeddown_Click(null, null);
                        e.Handled = true;
                        break;
                    case 32://抓怕
                        button_capture_Click(null, null);
                        e.Handled = true;
                        break;
                    case 13://保存
                        button_save_Click(null, null);
                        e.Handled = true;
                        break;
                    case 188://重拍1
                        if (I == 0)
                        {
                            index[0] = 0;
                            zoomPictureBox_1_1.zoomRequired = false;
                            zoomPictureBox_1_1.pictureBox1.Image = null;
                            File.Delete(PP.gTempFolder + "1_1.jpg");
                            File.Delete(PP.gTempFolder + "1_1.bmp");
                        }
                        if (I == 1)
                        {
                            index[1] = 0;
                            zoomPictureBox_2_1.zoomRequired = false;
                            zoomPictureBox_2_1.pictureBox1.Image = null;
                            File.Delete(PP.gTempFolder + "2_1.jpg");
                            File.Delete(PP.gTempFolder + "2_1.bmp");
                        }
                        if (I == 2)
                        {
                            index[2] = 0;
                            zoomPictureBox_3_1.zoomRequired = false;
                            zoomPictureBox_3_1.pictureBox1.Image = null;
                            File.Delete(PP.gTempFolder + "3_1.jpg");
                            File.Delete(PP.gTempFolder + "3_1.bmp");
                        }
                        if (I == 3)
                        {
                            index[3] = 0;
                            zoomPictureBox_4_1.zoomRequired = false;
                            zoomPictureBox_4_1.pictureBox1.Image = null;
                            File.Delete(PP.gTempFolder + "4_1.jpg");
                            File.Delete(PP.gTempFolder + "4_1.bmp");
                        }
                        if (I == 4)
                        {
                            index[4] = 0;
                            zoomPictureBox_5_1.zoomRequired = false;
                            zoomPictureBox_5_1.pictureBox1.Image = null;
                            File.Delete(PP.gTempFolder + "5_1.jpg");
                            File.Delete(PP.gTempFolder + "5_1.bmp");
                        }
                        e.Handled = true;
                        break;
                    case 190://重拍2
                        if (I == 0)
                        {
                            index[0] = 1;
                            zoomPictureBox_1_2.zoomRequired = false;
                            zoomPictureBox_1_2.pictureBox1.Image = null;
                            File.Delete(PP.gTempFolder + "1_2.jpg");
                            File.Delete(PP.gTempFolder + "1_2.bmp");
                        }
                        if (I == 1)
                        {
                            index[1] = 1;
                            zoomPictureBox_2_2.zoomRequired = false;
                            zoomPictureBox_2_2.pictureBox1.Image = null;
                            File.Delete(PP.gTempFolder + "2_2.jpg");
                            File.Delete(PP.gTempFolder + "2_2.bmp");
                        }
                        if (I == 2)
                        {
                            index[2] = 1;
                            zoomPictureBox_3_2.zoomRequired = false;
                            zoomPictureBox_3_2.pictureBox1.Image = null;
                            File.Delete(PP.gTempFolder + "3_2.jpg");
                            File.Delete(PP.gTempFolder + "3_2.bmp");
                        }
                        if (I == 3)
                        {
                            index[3] = 1;
                            zoomPictureBox_4_2.zoomRequired = false;
                            zoomPictureBox_4_2.pictureBox1.Image = null;
                            File.Delete(PP.gTempFolder + "4_2.jpg");
                            File.Delete(PP.gTempFolder + "4_2.bmp");
                        }
                        if (I == 4)
                        {
                            index[4] = 1;
                            zoomPictureBox_5_2.zoomRequired = false;
                            zoomPictureBox_5_2.pictureBox1.Image = null;
                            File.Delete(PP.gTempFolder + "5_2.jpg");
                            File.Delete(PP.gTempFolder + "5_2.bmp");
                        }
                        e.Handled = true;
                        break;
                    case 191://重拍3
                        if (I == 0)
                        {
                            index[0] = 2;
                            zoomPictureBox_1_3.zoomRequired = false;
                            zoomPictureBox_1_3.pictureBox1.Image = null;
                            File.Delete(PP.gTempFolder + "1_3.jpg");
                            File.Delete(PP.gTempFolder + "1_3.bmp");
                        }
                        if (I == 1)
                        {
                            index[1] = 2;
                            zoomPictureBox_2_3.zoomRequired = false;
                            zoomPictureBox_2_3.pictureBox1.Image = null;
                            File.Delete(PP.gTempFolder + "2_3.jpg");
                            File.Delete(PP.gTempFolder + "2_3.bmp");
                        }
                        if (I == 2)
                        {
                            index[2] = 2;
                            zoomPictureBox_3_3.zoomRequired = false;
                            zoomPictureBox_3_3.pictureBox1.Image = null;
                            File.Delete(PP.gTempFolder + "3_3.jpg");
                            File.Delete(PP.gTempFolder + "3_3.bmp");
                        }
                        if (I == 3)
                        {
                            index[3] = 2;
                            zoomPictureBox_4_3.zoomRequired = false;
                            zoomPictureBox_4_3.pictureBox1.Image = null;
                            File.Delete(PP.gTempFolder + "4_3.jpg");
                            File.Delete(PP.gTempFolder + "4_3.bmp");
                        }
                        if (I == 4)
                        {
                            index[4] = 2;
                            zoomPictureBox_5_3.zoomRequired = false;
                            zoomPictureBox_5_3.pictureBox1.Image = null;
                            File.Delete(PP.gTempFolder + "5_3.jpg");
                            File.Delete(PP.gTempFolder + "5_3.bmp");
                        }
                        e.Handled = true;
                        break;
                    case 112:
                    case 113:
                    case 114:
                    case 115:
                    case 116:
                    case 117:
                    case 118:
                    case 119:
                    case 120:
                    case 121:
                        if (m_CurrentCam != null) m_CurrentCam.CallPreSetPoint(e.KeyValue - 111);
                        e.Handled = true;
                        break;
                    default:
                        e.Handled = false;
                        break;
                }
            }
            catch { }
        }

        private void Form_Main_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                switch (e.KeyValue)
                {
                    case 38://上
                        button_up_MouseUp(null, null);
                        e.Handled = true;
                        break;
                    case 40://下
                        button_down_MouseUp(null, null);
                        e.Handled = true;
                        break;
                    case 37://左
                        button_left_MouseUp(null, null);
                        e.Handled = true;
                        break;
                    case 39://右
                        button_right_MouseUp(null, null);
                        e.Handled = true;
                        break;
                    case 186://拉近
                        button_near_MouseUp(null, null);
                        e.Handled = true;
                        break;
                    case 222://拉远
                        button_far_MouseUp(null, null);
                        e.Handled = true;
                        break;
                    default:
                        e.Handled = false;
                        break;
                }
            }
            catch { }
        }

        private void ToolStripMenuItem_upload_Click(object sender, EventArgs e)
        {
            UploadForm form = new UploadForm();
            form.Owner = this;
            form.ShowDialog();
            form.Dispose();
        }

        private void toolStripMenuItem_changepassword_Click(object sender, EventArgs e)
        {
            ChangeForm cf = new ChangeForm();
            cf.Owner = this;
            cf.ShowDialog();
            cf.Dispose();
        }

        private void toolStripMenuItem_yhgl_Click(object sender, EventArgs e)
        {
            UserForm form = new UserForm();
            form.Owner = this;
            form.ShowDialog();
            form.Dispose();
        }

        private void toolStripMenuItem_tongji_Click(object sender, EventArgs e)
        {
            TongJiForm form = new TongJiForm();
            form.Owner = this;
            form.ShowDialog();
            form.Dispose();
        }

        private void toolStripMenuItem_wfxwdm_Click(object sender, EventArgs e)
        {
            WFXWDMForm form = new WFXWDMForm();
            form.Owner = this;
            form.ShowDialog();
            form.Dispose();
        }

        private void ToolStripMenuItem_hpzl_Click(object sender, EventArgs e)
        {
            HPZLForm form = new HPZLForm();
            form.Owner = this;
            form.ShowDialog();
            form.Dispose();
        }

        private void tabControl2_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (tabControl2.SelectedIndex < 0) return;
                if (tabControl2.SelectedIndex < 5)
                {
                    I = tabControl2.SelectedIndex;
                    tabControl1.SelectedIndex = 0;
                    

                }
                if (tabControl2.SelectedIndex == 5)
                {
                    tabControl1.SelectedIndex = 1;
                }

                //增加视频代码


                if (m_CurrentCam != null)
                {

                    m_CurrentCam.ShutDown();

                    this.panel_play.Invalidate();
                    MessageBox.Show(m_CurrentCam.m_IP + "---第一个" + Convert.ToString(tabControl2.SelectedIndex));
                }
                for (int i = 0; i < 5; i++)
                {
                    if (a_CurrentCam[i] != null)
                    {
                        a_CurrentCam[i].ShutDown();
                        this.panel_play.Invalidate();
                        MessageBox.Show(a_CurrentCam[I].m_IP+"---第二个");

                    }
                }
                
                if (a_CurrentCam[I] == null)
                {
                    return;
                }
                string camip = a_CurrentCam[I].m_IP;
                //if ((a_CurrentCam[I] != null) && (camip == m_CurrentCam.m_IP) && (m_CurrentCam.m_CamIsOpen)) return;



                a_CurrentCam[I] = PP.FindCamByIP(camip);
                if (a_CurrentCam[I] != null)
                {
                    a_CurrentCam[I].Play(panel_play.Handle);
                    this.listBox_PreSetPoint.Items.Clear();
                    if ((a_CurrentCam[I].m_PreSetPonitHelpName != null) && (a_CurrentCam[I].m_PreSetPonitHelpName.Count > 0))
                    {
                        for (int i = 0; i < a_CurrentCam[I].m_PreSetPonitHelpName.Count; i++)
                        {
                            this.listBox_PreSetPoint.Items.Add((i + 1).ToString() + "---" + a_CurrentCam[I].m_PreSetPonitHelpName[i]);
                        }
                    }
                    a_CurrentCam[I].CheckTime();
                }
            }
            catch { }
        }

        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (tabControl1.SelectedIndex < 0) return;
            if (tabControl1.SelectedIndex == 0) tabControl2.SelectedIndex = I;
            if (tabControl1.SelectedIndex == 1) tabControl2.SelectedIndex = 5;
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (this.dataGridView1.SelectedRows.Count >= 1)
                {
                    string path1 = this.dataGridView1.SelectedRows[0].Cells["path1"].Value.ToString();
                    string path2 = this.dataGridView1.SelectedRows[0].Cells["path2"].Value.ToString();
                    string path3 = this.dataGridView1.SelectedRows[0].Cells["path3"].Value.ToString();
                    if (File.Exists(path1)) zoomPictureBox_his_1.pictureBox1.LoadAsync(path1);
                    if (File.Exists(path2)) zoomPictureBox_his_2.pictureBox1.LoadAsync(path2);
                    if (File.Exists(path3)) zoomPictureBox_his_3.pictureBox1.LoadAsync(path3);
                }
            }
            catch { }
        }

        private void splitContainer1_DoubleClick(object sender, EventArgs e)
        {
            if (this.splitContainer1.SplitterDistance <= 100)
            {
                this.splitContainer1.SplitterDistance = SplitterDistance2;
                return;
            }

            if (this.splitContainer1.SplitterDistance > 100)
            {
                this.splitContainer1.SplitterDistance = SplitterDistance1;
                return;
            }
        }

        private void tabControl_tree_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (this.tabControl_tree.SelectedIndex == 0)
                {
                    this.tabControl_view.SelectedIndex = 0;
                    //this.panel_play.Show();
                    //this.axDPSDK_OCX1.Hide();
                }
                else if (this.tabControl_tree.SelectedIndex == 1)
                {
                    //this.panel_play.Hide();
                    //this.axDPSDK_OCX1.Show();
                    this.tabControl_view.SelectedIndex = 1;
                    DSSLoad();
                }
            }
            catch { }
        }

        private void treeView2_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                if (treeView2.SelectedNode == null) return;
                if (treeView2.SelectedNode.Name != "Channel") return;
                if (I > 4) return;
                if (I < 0) return;
                string camid = treeView2.SelectedNode.Tag.ToString();

                if ((zoomPictureBox_1_1.pictureBox1.Image != null) ||
                    (zoomPictureBox_1_2.pictureBox1.Image != null) ||
                    (zoomPictureBox_1_3.pictureBox1.Image != null))
                {
                    this.toolStripStatusLabel_state.Text = "抓拍组一有未保存的违法证据，请先保存后再切换抓拍点位";
                    return;
                }

                if ((zoomPictureBox_2_1.pictureBox1.Image != null) ||
                    (zoomPictureBox_2_2.pictureBox1.Image != null) ||
                    (zoomPictureBox_2_3.pictureBox1.Image != null))
                {
                    this.toolStripStatusLabel_state.Text = "抓拍组二有未保存的违法证据，请先保存后再切换抓拍点位";
                    return;
                }

                if ((zoomPictureBox_3_1.pictureBox1.Image != null) ||
                    (zoomPictureBox_3_2.pictureBox1.Image != null) ||
                    (zoomPictureBox_3_3.pictureBox1.Image != null))
                {
                    this.toolStripStatusLabel_state.Text = "抓拍组三有未保存的违法证据，请先保存后再切换抓拍点位";
                    return;
                }

                if ((zoomPictureBox_4_1.pictureBox1.Image != null) ||
                    (zoomPictureBox_4_2.pictureBox1.Image != null) ||
                    (zoomPictureBox_4_3.pictureBox1.Image != null))
                {
                    this.toolStripStatusLabel_state.Text = "抓拍组四有未保存的违法证据，请先保存后再切换抓拍点位";
                    return;
                }

                if ((zoomPictureBox_5_1.pictureBox1.Image != null) ||
                    (zoomPictureBox_5_2.pictureBox1.Image != null) ||
                    (zoomPictureBox_5_3.pictureBox1.Image != null))
                {
                    this.toolStripStatusLabel_state.Text = "抓拍组五有未保存的违法证据，请先保存后再切换抓拍点位";
                    return;
                }

                //暂时不停止直连抓拍
                //if (m_CurrentCam != null)
                //{
                //    m_CurrentCam.ShutDown();
                //    this.panel_play.Invalidate();
                //}

                if ((m_camid != camid) && (camid != ""))
                {
                    m_camid = camid;
                    //this.axDPSDK_OCX1.DPSDK_StopRealplayByWndNo((uint)m_nSmartWndId, 0);
                    int flag = this.axDPSDK_OCX1.DPSDK_StartRealplayByWndNo((uint)m_nSmartWndId, 0, camid, 1, 1, 1);

                    if (flag != 0)
                    {
                        flag = this.axDPSDK_OCX1.DPSDK_GetLastError();
                        this.toolStripStatusLabel_state.Text = F.GetErrorText(flag);
                    }
                    else
                    {
                        this.listBox_PreSetPoint.Items.Clear();

                        for (int i = 0; i < 10; i++)
                        {
                            this.listBox_PreSetPoint.Items.Add((i + 1).ToString() + "---预置点" + (i + 1).ToString());
                        }

                    }
                }

            }
            catch { }
        }





        private void button_noparking_Click(object sender, EventArgs e)
        {
            //禁止停车标牌图叠加
            try
            {
                if (this.tabControl_tree.SelectedIndex == 0)
                {
                    if (m_CurrentCam != null)
                    {
                        string bzt = PP.gWorkFolder + "\\biaozhitu\\" + m_CurrentCam.m_RoadID + ".jpg";

                        if (File.Exists(bzt)==false)
                        {
                            byte[] picbytes = null;
                            bool flag = PP.kdws.JKZP_GetBZT(m_CurrentCam.m_RoadID + ".jpg", out picbytes);

                            if ((flag == true)&&(picbytes!=null))
                            {
                                File.WriteAllBytes(bzt, picbytes);
                            }

                        }

                        if (File.Exists(bzt) == true)
                        {
                            string temppic = PP.gTempFolder + (I + 1).ToString() + "_3.jpg";
                            string bmp3 = PP.gTempFolder + (I + 1).ToString() + "_3.bmp";
                            File.Delete(bmp3);
                            File.Copy(bzt, temppic, true);

                            Control[] cc = this.Controls.Find("zoomPictureBox_" + (I + 1).ToString() + "_3", true);
                            if ((cc != null) && (cc.Length > 0))
                            {
                                ZoomPictureBox box = (cc[0] as ZoomPictureBox);
                                box.pictureBox1.LoadAsync(temppic);
                            }

                            if (index[I] == 2)
                            {
                                index[I]++;//充当第三张
                            }
                        }
                    }
                }
                else
                {
                    if ((m_camid != "") && (treeView2.SelectedNode.Name == "Channel"))
                    {
                        string bzt = PP.gWorkFolder + "\\biaozhitu\\" + treeView2.SelectedNode.Parent.Tag.ToString() + ".jpg";

                        if (File.Exists(bzt) == false)
                        {
                            byte[] picbytes = null;
                            bool flag = PP.kdws.JKZP_GetBZT(treeView2.SelectedNode.Parent.Tag.ToString() + ".jpg", out picbytes);

                            if ((flag == true) && (picbytes != null))
                            {
                                File.WriteAllBytes(bzt, picbytes);
                            }

                        }

                        if (File.Exists(bzt) == true)
                        {
                            string temppic = PP.gTempFolder + (I + 1).ToString() + "_3.jpg";
                            File.Copy(bzt, temppic, true);

                            Control[] cc = this.Controls.Find("zoomPictureBox_" + (I + 1).ToString() + "_3", true);
                            if ((cc != null) && (cc.Length > 0))
                            {
                                ZoomPictureBox box = (cc[0] as ZoomPictureBox);
                                box.pictureBox1.LoadAsync(temppic);
                            }

                            if (index[I] == 2)
                            {
                                index[I]++;//充当第三张
                            }
                        }
                    }
                }
            }
            catch (Exception er)
            {
                this.toolStripStatusLabel_state.Text = er.Message;
            }
        }

        private void axDPSDK_OCX1_OnWndLBtnClick(object sender, AxDPSDK_OCXLib._DDPSDK_OCXEvents_OnWndLBtnClickEvent e)
        {
            try
            {
                if (m_camid != "")
                {
                    if (m_FlagRect == true)
                    {
                        m_FlagRect = false;
                    }
                    else
                    {
                        pointStart.X = e.xPos;
                        pointStart.Y = e.yPos;
                    }
                    

                    pointEnd.X = e.xPos;
                    pointEnd.Y = e.yPos;

                    Rectangle WinRect = new Rectangle(this.panel_play.Location, this.panel_play.Size);

                    Point Origin = new Point(0, 0);
                    Point SendPoint = new Point(0, 0);
                    Origin.X = (WinRect.Left + WinRect.Right) / 2;
                    Origin.Y = (WinRect.Top + WinRect.Bottom) / 2;

                    int dx = (pointStart.X + pointEnd.X) / 2;
                    int dy = (pointStart.Y + pointEnd.Y) / 2;

                    int width = WinRect.Right - WinRect.Left;
                    int height = WinRect.Bottom - WinRect.Top;

                    SendPoint.X = (dx - Origin.X) * 8192 * 2 / width;
                    SendPoint.Y = (dy - Origin.Y) * 8192 * 2 / height;

                    int width2 = pointEnd.X - pointStart.X;
                    int height2 = pointEnd.Y - pointStart.Y;
                    int multiple = 0;

                    if (height2 != 0 && width2 != 0)
                    {
                        multiple = (width * height) / (width2 * height2);
                    }
                    this.axDPSDK_OCX1.DPSDK_PtzSit(m_camid, SendPoint.X, SendPoint.Y, multiple);
                }


            }
            catch { }
        }

        private void axDPSDK_OCX1_OnWndRBtnClick(object sender, AxDPSDK_OCXLib._DDPSDK_OCXEvents_OnWndRBtnClickEvent e)
        {
            pointStart.X = e.xPos;
            pointStart.Y = e.yPos;
            m_FlagRect = true;
        }


        private void treeView2_MouseClick(object sender, MouseEventArgs e)
        {
            try
            {
                

                if (e.Button != MouseButtons.Right) return;
                if (treeView2.SelectedNode == null) return;

                this.toolStripMenuItem_add.Visible = true;//标志图
                this.toolStripMenuItem4.Visible = false;//添加路段
                this.toolStripMenuItem_delld.Visible = false;//删除路段
                this.toolStripMenuItem3.Visible = false;//关联路段


                if (treeView2.SelectedNode.Name == "Channel")
                {
                    if (PP.gUser.admin == true)
                    {
                        string camid = treeView2.SelectedNode.Tag.ToString();
                        string wfdddm = "";
                        if (PP.gDPSDK_WFDD.Contains(camid))
                        {
                            wfdddm = PP.gDPSDK_WFDD[camid].ToString();
                        }

                        Form_DPSDKWFDD form = new Form_DPSDKWFDD();
                        form.camid = camid;
                        form.wfdddm = wfdddm;
                        form.ShowDialog();
                        form.Dispose();
                    }
                    else
                    {
                        MessageBox.Show("要添加禁令标志图，请选择路口节点");
                    }
                }
            }
            catch { }
        }

        

        private void toolStripMenuItem_add_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.tabControl_tree.SelectedIndex == 0)
                {
                    if (treeView1.SelectedNode.Name=="road")
                    {
                        string bzt = PP.gWorkFolder + "\\biaozhitu\\" + treeView1.SelectedNode.Tag.ToString() + ".jpg";

                        if (DialogResult.OK == openFileDialog1.ShowDialog())
                        {
                            if (openFileDialog1.FileName != "")
                            {
                                File.Copy(openFileDialog1.FileName, bzt, true);
                                bool flag = PP.kdws.JKZP_AddBZT(treeView1.SelectedNode.Tag.ToString() + ".jpg", File.ReadAllBytes(openFileDialog1.FileName));
                                if (flag == true)
                                {
                                    this.toolStripStatusLabel_state.Text = "添加禁令标志图成功";
                                }
                                else
                                {
                                    this.toolStripStatusLabel_state.Text = "添加禁令标志图失败";
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (treeView2.SelectedNode.Name == "Department")
                    {
                        string bzt = PP.gWorkFolder + "\\biaozhitu\\" + treeView2.SelectedNode.Tag.ToString() + ".jpg";

                        if (DialogResult.OK == openFileDialog1.ShowDialog())
                        {
                            if (openFileDialog1.FileName != "")
                            {
                                File.Copy(openFileDialog1.FileName, bzt, true);
                                bool flag = PP.kdws.JKZP_AddBZT(treeView2.SelectedNode.Tag.ToString() + ".jpg", File.ReadAllBytes(openFileDialog1.FileName));
                                if (flag == true)
                                {
                                    this.toolStripStatusLabel_state.Text = "添加禁令标志图成功";
                                }
                                else
                                {
                                    this.toolStripStatusLabel_state.Text = "添加禁令标志图失败";
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception er)
            {
                this.toolStripStatusLabel_state.Text = "添加禁令标志图异常" + er.Message;
            }
        }

        private void treeView1_MouseClick(object sender, MouseEventArgs e)
        {
            try
            {
                if (e.Button != MouseButtons.Right) return;
                if (treeView1.SelectedNode == null) return;
                if (treeView1.SelectedNode.Name == "root")
                {
                    if (PP.gUser.admin == true)
                    {
                        this.toolStripMenuItem_add.Visible = false;//标志图
                        this.toolStripMenuItem4.Visible = true;//添加路段
                        this.toolStripMenuItem_delld.Visible = false;//删除路段
                        this.toolStripMenuItem3.Visible = false;//关联路段
                    }
                    else
                    {
                        MessageBox.Show("无添加路段权限");
                    }
                }
                else if (treeView1.SelectedNode.Name == "luduan")
                {
                    if (PP.gUser.admin == true)
                    {
                        this.toolStripMenuItem_add.Visible = false;//标志图
                        this.toolStripMenuItem4.Visible = false;//添加路段
                        this.toolStripMenuItem_delld.Visible = true;//删除路段
                        this.toolStripMenuItem3.Visible = false;//关联路段
                    }
                    else
                    {
                        MessageBox.Show("无删除路段权限");
                    }
                }
                else if (treeView1.SelectedNode.Name == "road")
                {
                    if (PP.gUser.admin == true)
                    {
                        this.toolStripMenuItem_add.Visible = true;//标志图
                        this.toolStripMenuItem4.Visible = false;//添加路段
                        this.toolStripMenuItem_delld.Visible = false;//删除路段
                        if (treeView1.SelectedNode.Parent.Name == "root")
                        {
                            this.toolStripMenuItem3.Visible = true;//关联路段
                        }
                        else
                        {
                            this.toolStripMenuItem3.Visible = false;//关联路段
                        }
                    }
                    else
                    {
                        this.toolStripMenuItem_add.Visible = true;//标志图
                        this.toolStripMenuItem4.Visible = false;//添加路段
                        this.toolStripMenuItem_delld.Visible = false;//删除路段
                        this.toolStripMenuItem3.Visible = false;//关联路段
                    }
                }
                else if (treeView1.SelectedNode.Name == "camera")
                {
                    this.toolStripMenuItem_add.Visible = false;//标志图
                    this.toolStripMenuItem4.Visible = false;//添加路段
                    this.toolStripMenuItem_delld.Visible = false;//删除路段
                    this.toolStripMenuItem3.Visible = false;//关联路段
                    MessageBox.Show("要添加标志图，请选择路口节点");
                }
            }
            catch { }
        }

        private void toolStripMenuItem_addld_Click(object sender, EventArgs e)
        {
            //addld
            try
            {
                if ((toolStripTextBox_addld.Text != "") &&
                    (!toolStripTextBox_addld.Text.Contains("-")))
                {
                    if (!PP.gLuDuanList.Contains(toolStripTextBox_addld.Text))
                    {
                        bool flag = PP.kdws.JKZP_AddLuDuan(toolStripTextBox_addld.Text);
                        if (flag == true)
                        {
                            PP.gLuDuanList.Add(toolStripTextBox_addld.Text);
                            TreeNode luduannode = new TreeNode();
                            luduannode.Name = "luduan";
                            luduannode.Text = toolStripTextBox_addld.Text;
                            luduannode.Tag = toolStripTextBox_addld.Text;
                            luduannode.ImageIndex = 0;
                            luduannode.SelectedImageIndex = 0;
                            this.treeView1.Nodes[0].Nodes.Add(luduannode);

                            toolStripComboBox_glld.Items.Clear();
                            toolStripComboBox_glld.Items.AddRange(PP.gLuDuanList.ToArray());

                            this.toolStripStatusLabel_state.Text = "添加路段成功：" + toolStripTextBox_addld.Text;
                        }
                        else
                        {
                            this.toolStripStatusLabel_state.Text = "添加路段失败：" + toolStripTextBox_addld.Text;
                        }
                    }
                    else
                    {
                        this.toolStripStatusLabel_state.Text = "已经存在该路段：" + toolStripTextBox_addld.Text;
                    }
                }
                else
                {
                    this.toolStripStatusLabel_state.Text = "路段名称为不能为空，且不能含有字符'-'";
                }
            }
            catch (Exception er)
            {
                this.toolStripStatusLabel_state.Text = "添加路段异常" + er.Message;
            }
        }

        private void toolStripMenuItem_delld_Click(object sender, EventArgs e)
        {
            //delld
            try
            {
                if (this.treeView1.SelectedNode.Name == "luduan")
                {
                    string luduan = this.treeView1.SelectedNode.Text;
                    TreeNode root = this.treeView1.Nodes[0];

                    bool flag = PP.kdws.JKZP_DelLuDuan(luduan);
                    if (flag == true)
                    {
                        TreeNode thisnode = (TreeNode)this.treeView1.SelectedNode.Clone();

                        if (thisnode.Nodes.Count > 0)
                        {
                            foreach (TreeNode node in thisnode.Nodes)
                            {
                                root.Nodes.Add(node);
                            }
                        }
                        root.Nodes.Remove(this.treeView1.SelectedNode);

                        PP.gLuDuanList.Remove(luduan);

                        toolStripComboBox_glld.Items.Clear();
                        toolStripComboBox_glld.Items.AddRange(PP.gLuDuanList.ToArray());

                        this.toolStripStatusLabel_state.Text = "删除路段成功" + luduan;
                    }
                    else
                    {
                        this.toolStripStatusLabel_state.Text = "删除路段失败" + luduan;
                    }
                }
            }
            catch (Exception er)
            {
                this.toolStripStatusLabel_state.Text = "删除路段异常" + er.Message;
            }
        }

        private void toolStripMenuItem_glld_Click(object sender, EventArgs e)
        {
            //glld
            try
            {
                if (this.treeView1.SelectedNode.Name == "road")
                {
                    if (toolStripComboBox_glld.Text != "")
                    {
                        string roadid = this.treeView1.SelectedNode.Tag.ToString();
                        string luduan = toolStripComboBox_glld.Text;
                        TreeNode root = this.treeView1.Nodes[0];

                        bool flag = PP.kdws.JKZP_SetLuDuan(roadid, luduan);
                        if (flag == true)
                        {
                            for(int i=0;i< root.Nodes.Count;i++)
                            {
                                if ((root.Nodes[i].Name == "luduan")&& (root.Nodes[i].Text == luduan))
                                {
                                    TreeNode thisnode = (TreeNode)this.treeView1.SelectedNode.Clone();
                                    root.Nodes[i].Nodes.Add(thisnode);
                                    break;
                                }
                            }

                            root.Nodes.Remove(this.treeView1.SelectedNode);
                            this.toolStripStatusLabel_state.Text = "关联路段成功" + luduan;
                        }
                        else
                        {
                            this.toolStripStatusLabel_state.Text = "关联路段失败" + luduan;
                        }
                    }
                }
            }
            catch(Exception er)
            {
                this.toolStripStatusLabel_state.Text = "关联路段异常" + er.Message;
            }
        }

        private void tabControl2_Selecting(object sender, TabControlCancelEventArgs e)
        {
            //MessageBox.Show(Convert.ToString(tabControl2.));
        }
    }
}
